package oneroom.user.area;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import oneroom.comm.IbatisLoader;

import com.ibatis.sqlmap.client.SqlMapClient;

public class areaDao {
	private IbatisLoader 	iBatis;
	private SqlMapClient 	sqlMapper;
	
	public areaDao(){
		this.sqlMapper = iBatis.setConfig();
	}
	/**
	 * 서울 지역 탑 10건
	 * @return
	 */
	public List getSeaul(String roomkind, int size){
		List returnValue = new ArrayList();
		HashMap param = new HashMap();
		param.put("param", "서울");
		param.put("roomkind",roomkind);
		param.put("size",size);
		try{
			returnValue = (List)sqlMapper.queryForList("area.areaone",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 경기 지역 탑 10건
	 * @return
	 */
	public List getKeayki(String roomkind, int size){ 
		List returnValue = new ArrayList();
		HashMap param = new HashMap();
		param.put("param", "경기");
		param.put("roomkind",roomkind);
		param.put("size",size);
		try{
			returnValue = (List)sqlMapper.queryForList("area.areaone",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 전국 탑 10건
	 * @return
	 */
	public List getRoom(String roomkind, int size){
		List returnValue = new ArrayList();
		HashMap param = new HashMap();
		param.put("param", "서울");
		param.put("param1", "경기");
		param.put("roomkind", roomkind);
		param.put("size",size);
		try{
			returnValue = (List)sqlMapper.queryForList("area.areaonecountry",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 게시판 최근 5건
	 * @param searchBoard
	 * @return
	 */
	public List getBoard(String searchBoard){
		List returnValue = new ArrayList();
		try{
			returnValue = (List)sqlMapper.queryForList("area.areaboard",searchBoard);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 서울 이나 경기 전국 을 선택 하였을 경우
	 * @param roomkind
	 * @param size
	 * @param param
	 * @return
	 */
	public List getRooms(String roomkind, int size, String param){
		List returnValue = new ArrayList();
		HashMap params = new HashMap();
		params.put("param", param);
		params.put("roomkind", roomkind);
		params.put("size",size);
		try{
			returnValue = (List)sqlMapper.queryForList("area.room",params);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	public List getAllRooms(String roomkind, int size, String param){
		List returnValue = new ArrayList();
		HashMap params = new HashMap();
		params.put("param1", "서울");
		params.put("param2", "경기");
		params.put("roomkind", roomkind);
		params.put("size",size);
		try{
			returnValue = (List)sqlMapper.queryForList("area.allroom",params);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	/**
	 * 서울 경기 선택  구를 선택 하였을 경우
	 * @param roomkind
	 * @param size
	 * @param param
	 * @return
	 */
	public List getGuRooms(String roomkind, int size, String param){
		List returnValue = new ArrayList();
		HashMap params = new HashMap();
		params.put("param", param);
		params.put("roomkind", roomkind);
		params.put("size",size);
		try{
			returnValue = (List)sqlMapper.queryForList("area.guroom",params);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	/**
	 * 서울 경기 선택  동를 선택 하였을 경우
	 * @param roomkind
	 * @param area
	 * @param sort
	 * @param selectPage
	 * @param pageSize
	 * @return
	 */
	public List getDongRooms(String roomkind, //임대종류
			String area, //임대형태
			String sort,
			int selectPage,
			int pageSize){ 
	List returnValue = new ArrayList();
	/* 
	* 페이징 관련
	*/
	if (selectPage == 0) selectPage = 1;
	if (pageSize == 0) pageSize = 10;
	int startPos = ((selectPage-1)*pageSize);
	
	HashMap param = new HashMap();
	param.put("roomkind", roomkind);
	param.put("address3", area);
	param.put("sort", sort);
	param.put("startPos", startPos);
	param.put("pageSize", pageSize);
	try{
	returnValue = (List)sqlMapper.queryForList("area.addressseche",param);
	}catch (Exception e) {
	// TODO: handle exception
	}
	return returnValue;
	
	}
	/**
	 * 서울 경기 동 전체 객수
	 * @param roomkind
	 * @param area
	 * @param sort
	 * @return
	 */
	public int getDongCount(String roomkind, //임대종류
			String area, //임대형태
			String sort){ 
	int  returnValue = 0;
	
	HashMap param = new HashMap();
	param.put("roomkind", roomkind);
	param.put("address3", area);
	param.put("sort", sort);
	try{
	returnValue = ((Integer)sqlMapper.queryForObject("area.addresssechecnt",param)).intValue();
	
	}catch (Exception e) {
	// TODO: handle exception
	}
	return returnValue;
	
	}
	

}
